package com.swt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swt.domain.Goods;
import com.swt.service.GoodsCommentService;
import com.swt.domain.GoodsComment;
import com.swt.mapper.GoodsCommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 苏
* @description 针对表【okayapi_goods_comment(商品评价)】的数据库操作Service实现
* @createDate 2022-05-16 09:40:37
*/
@Service
public class GoodsCommentServiceImpl implements GoodsCommentService {
    @Autowired
    private GoodsCommentMapper GoodsCommentMapper;
    @Override
    public List<GoodsComment> selectAllGoodsComment() {
        return GoodsCommentMapper.selectList(null);
    }

    @Override
    public int delectGoodsComment(String id) {
        return GoodsCommentMapper.deleteById(id);
    }

    @Override
    public int updateGoodsComment(GoodsComment goodsComment) {
        return GoodsCommentMapper.updateById(goodsComment);
    }

    @Override
    public int inserGoodsComment(GoodsComment goodsComment) {
        return GoodsCommentMapper.insert(goodsComment);
    }

    @Override
    public GoodsComment selectbyGoodsCommentid(String id) {
        return GoodsCommentMapper.selectById(id);
    }

    @Override
    public Page<GoodsComment> pageGoodsComment(Integer page, Integer start,GoodsComment goodsComment) {
        Page<GoodsComment> userPage = new Page<>(page,start);
        LambdaQueryWrapper<GoodsComment> lqw = new LambdaQueryWrapper<>();
        lqw.orderByDesc(GoodsComment::getCreateTime);
        if (goodsComment != null ){
            lqw.like(StringUtils.isNotEmpty(goodsComment.getCommentBuyer()),GoodsComment::getCommentBuyer,goodsComment.getCommentBuyer());

        }
        return GoodsCommentMapper.selectPage(userPage,lqw);
    }
}




